package com.woniuxy.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.goods.entity.ProcessExecute;
import com.woniuxy.goods.entity.ProcessModel;
import com.woniuxy.goods.mapper.ProcessModelMapper;
import com.woniuxy.goods.service.ProcessModelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 * 流程模型服务层实现类
 * @author ...
 * @since 2024年05月22日
 */
@Service
public class ProcessModelServiceImpl extends ServiceImpl<ProcessModelMapper, ProcessModel> implements ProcessModelService {

    /**
     * 根据流程id查出对应流程模型
     * @param processId 流程id
     * @return 流程模型
     * @throws Exception
     */
    @Override
    public List<ProcessModel> findModelByProcessId(Integer processId) {
        QueryWrapper<ProcessModel> wrapper = new QueryWrapper<>();
        wrapper.eq("process_id",processId);
        return list(wrapper);
    }

    /**
     * 根据流程码查出对应流程状态名称
     * @param stateNUm 流程码
     * @param processId 流程id
     * @return 流程状态名称
     * @throws Exception
     */
    @Override
    public String findStateNameByNum(Integer stateNUm, Integer processId) throws Exception {
        QueryWrapper<ProcessModel> wrapper = new QueryWrapper<>();
        wrapper.eq("state_num",stateNUm);
        wrapper.eq("process_id",processId);
        ProcessModel model = getOne(wrapper);
        if (model==null) throw new Exception("流程不存在");
        return model.getStateName();
    }
}
